﻿using EPE.BLL;
using EPE.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EPE.WPF
{
    /// <summary>
    /// BuildAddForm.xaml 的交互逻辑
    /// </summary>
    public partial class BuildAddForm : Window
    {
        public BuildAddForm()
        {
            InitializeComponent();
        }

        CLoginUser userinfo = new CLoginUser();
        public BuildAddForm(CLoginUser pargUserinfo)
        {
            InitializeComponent();
            userinfo = pargUserinfo;

            ShopsProject bll = new ShopsProject();
            this.cmbProject.ItemsSource = bll.GetAllList(userinfo.CompanyId.ToString()).Tables[0].DefaultView;
            this.cmbProject.SelectedValuePath = "projectid";
            this.cmbProject.DisplayMemberPath = "projectname";
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            CShopsBuild model = new CShopsBuild();

            model.projectid = Convert.ToInt32(((DataRowView)this.cmbProject.SelectedItem).Row.ItemArray[0]);
            model.buildname = this.txtBuildName.Text;
            model.buildfuction = this.txtFunction.Text;
            model.alllayer = Convert.ToInt32(this.txtAllLayer.Text);
            model.groudlayer = Convert.ToInt32(this.txtGroudLayer.Text);
            model.startdate = Convert.ToDateTime(this.dpStartDate.SelectedDate);
            model.enddate = Convert.ToDateTime(this.dpEndDate.SelectedDate);
            model.located = this.txtLocated.Text;
            model.area = Convert.ToDecimal(this.txtArea.Text);
            model.buildarea = Convert.ToDecimal(this.txtBuildArea.Text);
            model.property = this.txtProperty.Text;

            ShopsBuild bll = new ShopsBuild();

            bll.Insert(model);

            MessageBox.Show("保存成功！", "系统信息", MessageBoxButton.OK, MessageBoxImage.Information);

            this.Close();
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

    }
}
